package BookCreated;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import BookDB.h2DB;
import Loginout.UserBean;

import java.util.List;

@SuppressWarnings("unused")
@WebServlet("/editbook")
public class EditBook extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		UserBean UB = (UserBean) session.getAttribute("ub");
		
		if (UB == null) {
			response.sendRedirect("error.html");
		} else {
			response.setContentType("text/html;charset=UTF-8");
			request.setCharacterEncoding("UTF-8");

			String bookid = request.getParameter("bookid");
			Books b = null;
			try {
				b = BooksDAO.GetbooksformDB(bookid);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if (b != null) {
				session.setAttribute("sessionBook", b);
				Books book = (Books) session.getAttribute("sessionBook");

				request.setAttribute("ebook", b);
				request.getRequestDispatcher("EditBookPage.jsp").forward(
						request, response);
			} else {
				response.getWriter().print("Not Found Books!");
			}
		} 
	}
}
